﻿using System;
using System.Drawing;

namespace Felbot.Interface.Users {
    /// <summary>This represents a user's stat stirng and contains all parsed information.</summary>
    public class UserStats {
        #region Fields
        private string m_ClientCode = "";
        private string m_ClientName = "Unknown";
        private string m_RawStatstring;
        private string m_ParsedStatstring;
        private int m_IconIndex = 1;
        private string m_ClanTag = "";
        private bool m_Spawn = false;
        private DiabloStats m_DiabloStats = null;
        private StarCraftStats m_StarCraftStats = null;
        private Diablo2Stats m_Diablo2Stats = null;
        private WarCraft2Stats m_WarCraft2Stats = null;
        private WarCraft3Stats m_WarCraft3Stats = null;
        #endregion

        #region Clients Inspecific Properties
        /// <summary>Gets the raw client name the user is using.</summary>
        public string ClientCode {
            get {
                return m_ClientCode;
            }
        }

        /// <summary>Gets the parsed client name the user is using.</summary>
        public string ClientName {
            get {
                return m_ClientName;
            }
        }

        /// <summary>Gats the stat string that this object represents.</summary>
        public string RawStatString {
            get {
                return m_RawStatstring;
            }
        }

        /// <summary>Gets the information to display for this user.</summary>
        public string ParsedStatString {
            get {
                return m_ParsedStatstring;
            }
        }

        /// <summary>Gets the icon index of the client-specific icon found for this statstring.</summary>
        public int IconIndex {
            get {
                return m_IconIndex;
            }
        }

        /// <summary>Gets the client-inspecific clan tag used in the channel list. (WarCraft III only right now, otherwise "")</summary>
        public string ClanTag {
            get {
                return m_ClanTag;
            }
        }

        /// <summary>Gets whether this client is a Spawn.</summary>
        public bool Spawn {
            get {
                return m_Spawn;
            }
        }
        #endregion

        #region Client Property Objects
        /// <summary>Gets an object containing Diablo Retail and Shareware stats, or returns null if not a Diablo user.</summary>
        public DiabloStats Diablo {
            get {
                return m_DiabloStats;
            }
        }

        /// <summary>Gets an object containing StarCraft Original, Broodwar, Japan, and Shareware stats, or returns null if not a StarCraft user.</summary>
        public StarCraftStats StarCraft {
            get {
                return m_StarCraftStats;
            }
        }

        /// <summary>Gets an object containing WarCraft II BNE stats, or returns null if not a WarCraft II user.</summary>
        public WarCraft2Stats WarCraft2 {
            get {
                return m_WarCraft2Stats;
            }
        }

        /// <summary>Gets an object containing Diablo II and LOD stats, or returns null if not a Diablo II user.</summary>
        public Diablo2Stats Diablo2 {
            get {
                return m_Diablo2Stats;
            }
        }

        /// <summary>Gets an object containing WarCraft III ROC and TFT stats, or returns null if not a WarCraft III user.</summary>
        public WarCraft3Stats WarCraft3 {
            get {
                return m_WarCraft3Stats;
            }
        }
        #endregion

        /// <summary>Creates a new statstring object from the statstring provided. This will completely parse the statstring!</summary>
        /// <param name="a_sStatstring">The statstring.</param>
        public UserStats(string statstring) {
            if (statstring == null || statstring == "")
                throw new ArgumentNullException("statstring", "Statstring cannot be null.");

            m_RawStatstring = statstring;
            string[] splitstats = statstring.Split(' ');
            if (splitstats.Length >= 1) {
                m_ClientCode = splitstats[0];
                int tempValue = 0;
                int[] stats = new int[10];
                switch (ClientCode) {
                    case "DSHR":
                    case "RHSD":
                        m_ClientName = "Diablo: Shareware";
                        m_ParsedStatstring = m_ClientName;
                        m_IconIndex = 4; // Diablo icon
                        break;
                    case "DRTL":
                    case "LTRD":
                        m_ClientName = "Diablo";
                        for (int i = 1; i < splitstats.Length && i < 11; i++) {
                            if (int.TryParse(splitstats[i], out tempValue))
                                stats[i] = tempValue;
                            else
                                stats[i] = -1;
                        }
                        m_DiabloStats = new DiabloStats(stats);
                        m_ParsedStatstring = m_ClientName + " ";
                        if (m_DiabloStats.Level > 0) {
                            m_ParsedStatstring += "(Level " + m_DiabloStats.Level.ToString() + " ";
                            if (m_DiabloStats.Class != null)
                                m_ParsedStatstring += m_DiabloStats.Class + " ";
                            if (m_DiabloStats.Dots > 0 && m_DiabloStats.Dots < 4)
                                m_ParsedStatstring += "who has completed the " + m_DiabloStats.LastDifficultyCompleted + " difficulty,";
                            if (m_DiabloStats.Strength >= 0)
                                m_ParsedStatstring += " with " + m_DiabloStats.Strength + " strength,";
                            if (m_DiabloStats.Magic >= 0)
                                m_ParsedStatstring += " " + m_DiabloStats.Magic + " magic,";
                            if (m_DiabloStats.Dexterity >= 0)
                                m_ParsedStatstring += " " + m_DiabloStats.Dexterity + " dexterity,";
                            if (m_DiabloStats.Vitality >= 0)
                                m_ParsedStatstring += " " + m_DiabloStats.Vitality + " vitality,";
                            if (m_DiabloStats.Gold >= 0)
                                m_ParsedStatstring += " " + m_DiabloStats.Gold + " gold,";
                        }
                        m_ParsedStatstring = m_ParsedStatstring.Substring(0, m_ParsedStatstring.Length - 1);
                        if (m_ParsedStatstring == m_ClientName) {
                            if (stats[0] >= 0) {
                                m_ParsedStatstring += " (" + statstring + ")";
                            }
                        } else {
                            m_ParsedStatstring += ")";
                        }
                        m_IconIndex = 4; // Diablo icon
                        break;
                    case "SSHR":
                    case "RHSS":
                        m_ClientName = "StarCraft: Shareware";
                        m_ParsedStatstring = m_ClientName;
                        m_IconIndex = 2; // StarCraft icon
                        break;
                    case "JSTR":
                    case "RTSJ":
                        m_ClientName = "StarCraft: Japan";
                        for (int i = 1; i < splitstats.Length && i < 10; i++) {
                            if (int.TryParse(splitstats[i], out tempValue))
                                stats[i] = tempValue;
                            else
                                stats[i] = -1;
                        }
                        m_StarCraftStats = new StarCraftStats(stats, splitstats[9]);
                        m_ParsedStatstring = m_ClientName + " ";
                        if (m_StarCraftStats.Wins >= 0)
                            m_ParsedStatstring += "(" + m_StarCraftStats.Wins.ToString() + " wins,";
                        if (m_StarCraftStats.Spawned) {
                            m_Spawn = true;
                            m_ParsedStatstring += " Spawned,";
                        }
                        if (m_StarCraftStats.IconName != "Normal")
                            m_ParsedStatstring += " " + m_StarCraftStats.IconName + " icon,";
                        m_ParsedStatstring = m_ParsedStatstring.Substring(0, m_ParsedStatstring.Length - 1);
                        if (m_ParsedStatstring != m_ClientName)
                            m_ParsedStatstring += ")";
                        m_IconIndex = 2; // StarCraft icon
                        break;
                    case "STAR":
                    case "RATS":
                        m_ClientName = "StarCraft";
                        for (int i = 1; i < splitstats.Length && i < 10; i++) {
                            if (int.TryParse(splitstats[i], out tempValue))
                                stats[i] = tempValue;
                            else
                                stats[i] = -1;
                        }
                        m_StarCraftStats = new StarCraftStats(stats, splitstats[9]);
                        m_ParsedStatstring = m_ClientName + " ";
                        if (m_StarCraftStats.Wins >= 0)
                            m_ParsedStatstring += "(" + m_StarCraftStats.Wins.ToString() + " wins,";
                        if (m_StarCraftStats.Spawned) {
                            m_Spawn = true;
                            m_ParsedStatstring += " Spawned,";
                        }
                        if (m_StarCraftStats.IconName != "Normal")
                            m_ParsedStatstring += " " + m_StarCraftStats.IconName + " icon,";
                        m_ParsedStatstring = m_ParsedStatstring.Substring(0, m_ParsedStatstring.Length - 1);
                        if (m_ParsedStatstring != m_ClientName)
                            m_ParsedStatstring += ")";
                        m_IconIndex = 2; // StarCraft icon
                        break;
                    case "SEXP":
                    case "PXES":
                        m_ClientName = "StarCraft: Brood War";
                        for (int i = 1; i < splitstats.Length && i < 10; i++) {
                            if (int.TryParse(splitstats[i], out tempValue))
                                stats[i] = tempValue;
                            else
                                stats[i] = -1;
                        }
                        m_StarCraftStats = new StarCraftStats(stats, splitstats[9]);
                        m_ParsedStatstring = m_ClientName + " ";
                        if (m_StarCraftStats.Wins >= 0)
                            m_ParsedStatstring += "(" + m_StarCraftStats.Wins.ToString() + " wins,";
                        /*if (m_StarCraftStats.Spawned) {
                            m_Spawn = true;
                            m_ParsedStatstring += " Spawned,";
                        }*cannot be spawned!*/
                        if (m_StarCraftStats.IconName != "Normal")
                            m_ParsedStatstring += " " + m_StarCraftStats.IconName + " icon,";
                        m_ParsedStatstring = m_ParsedStatstring.Substring(0, m_ParsedStatstring.Length - 1);
                        if (m_ParsedStatstring != m_ClientName)
                            m_ParsedStatstring += ")";
                        m_IconIndex = 3; // StarCraft BW icon
                        break;
                    case "W2BN":
                    case "NB2W":
                        m_ClientName = "WarCraft II: Battle.net Edition";
                        for (int i = 1; i < splitstats.Length && i < 10; i++) {
                            if (int.TryParse(splitstats[i], out tempValue))
                                stats[i] = tempValue;
                            else
                                stats[i] = -1;
                        }
                        m_WarCraft2Stats = new WarCraft2Stats(stats, splitstats[9]);
                        m_ParsedStatstring = m_ClientName + " ";
                        if (m_WarCraft2Stats.Wins >= 0)
                            m_ParsedStatstring += "(" + m_WarCraft2Stats.Wins.ToString() + " wins,";
                        if (m_WarCraft2Stats.Spawned) {
                            m_Spawn = true;
                            m_ParsedStatstring += " Spawned,";
                        }
                        if (m_WarCraft2Stats.IconName != "Normal")
                            m_ParsedStatstring += " " + m_WarCraft2Stats.IconName + " icon,";
                        m_ParsedStatstring = m_ParsedStatstring.Substring(0, m_ParsedStatstring.Length - 1);
                        if (m_ParsedStatstring != m_ClientName)
                            m_ParsedStatstring += ")";
                        m_IconIndex = 7; // WarCraft II BNE icon
                        break;
                    case "D2DV":
                    case "VD2D":
                        m_ClientName = "Diablo II";
                        m_ParsedStatstring = m_ClientName + " (Not on Realm)";
                        m_Diablo2Stats = new Diablo2Stats();
                        m_IconIndex = 5; // Diablo II icon
                        break;
                    case "D2XP":
                    case "PX2D":
                        m_ClientName = "Diablo II: Lord of Destruction";
                        m_ParsedStatstring = m_ClientName + " (Not on Realm)";
                        m_Diablo2Stats = new Diablo2Stats();
                        m_IconIndex = 6; // Diablo II Expansion icon
                        break;
                    case "WAR3":
                    case "3RAW":
                        m_ClientName = "WarCraft III";
                        m_WarCraft3Stats = new WarCraft3Stats(splitstats);
                        m_ParsedStatstring = m_ClientName + " ";
                        if (m_WarCraft3Stats.Level > 0)
                            m_ParsedStatstring += "(Level " + m_WarCraft3Stats.Level.ToString() + ",";
                        if (m_WarCraft3Stats.IconName != "Normal") {
                            if (m_ParsedStatstring == m_ClientName + " ")
                                m_ParsedStatstring += "(";
                            else
                                m_ParsedStatstring += " ";
                            m_ParsedStatstring += m_WarCraft3Stats.IconName + " icon,";
                        }
                        if (m_WarCraft3Stats.ClanTag != "") {
                            if (m_ParsedStatstring == m_ClientName + " ")
                                m_ParsedStatstring += "(";
                            else
                                m_ParsedStatstring += " ";
                            m_ParsedStatstring += "Clan " + m_WarCraft3Stats.ClanTag + ",";
                            m_ClanTag = m_WarCraft3Stats.ClanTag;
                        }
                        m_ParsedStatstring = m_ParsedStatstring.Substring(0, m_ParsedStatstring.Length - 1);
                        if (m_ParsedStatstring != m_ClientName)
                            m_ParsedStatstring += ")";
                        m_IconIndex = 8; // WarCraft III icon
                        break;
                    case "W3XP":
                    case "PX3W":
                        m_ClientName = "WarCraft III: The Frozen Throne";
                        m_WarCraft3Stats = new WarCraft3Stats(splitstats);
                        m_ParsedStatstring = m_ClientName + " ";
                        if (m_WarCraft3Stats.Level > 0)
                            m_ParsedStatstring += "(Level " + m_WarCraft3Stats.Level.ToString() + ",";
                        if (m_WarCraft3Stats.IconName != "Normal") {
                            if (m_ParsedStatstring == m_ClientName + " ")
                                m_ParsedStatstring += "(";
                            else
                                m_ParsedStatstring += " ";
                            m_ParsedStatstring += m_WarCraft3Stats.IconName + " icon,";
                        }
                        if (m_WarCraft3Stats.ClanTag != "") {
                            if (m_ParsedStatstring == m_ClientName + " ")
                                m_ParsedStatstring += "(";
                            else
                                m_ParsedStatstring += " ";
                            m_ParsedStatstring += "Clan " + m_WarCraft3Stats.ClanTag + ",";
                            m_ClanTag = m_WarCraft3Stats.ClanTag;
                        }
                        m_ParsedStatstring = m_ParsedStatstring.Substring(0, m_ParsedStatstring.Length - 1);
                        if (m_ParsedStatstring != m_ClientName)
                            m_ParsedStatstring += ")";
                        m_IconIndex = 9; // WarCraft III TFT icon
                        break;
                    case "CHAT":
                    case "TAHC":
                        m_ClientName = "Chat Client";
                        m_ParsedStatstring = m_ClientName;
                        m_IconIndex = 1; // Chat icon
                        break;
                    default:
                        // Diablo II?
                        m_ClientName = statstring.Substring(0, 4);
                        switch (ClientName) {
                            case "VD2D":
                                m_ClientName = "Diablo II";
                                m_ParsedStatstring = m_ClientName;
                                m_IconIndex = 5; // Diablo II icon
                                break;
                            case "PX2D":
                                m_ClientName = "Diablo II: Lord of Destruction";
                                m_ParsedStatstring = m_ClientName;
                                m_IconIndex = 6; // Diablo II Expansion icon
                                break;
                            default:
                                m_ClientName = "Unknown";
                                m_ParsedStatstring = m_ClientName;
                                m_IconIndex = 1; // Chat icon
                                return;
                        }

                        // Diablo II Realm Parsing
                        m_Diablo2Stats = new Diablo2Stats(statstring.Substring(4).Split(",".ToCharArray(), 3));
                        m_ParsedStatstring += " (Realm " + m_Diablo2Stats.RealmName + ", character " + m_Diablo2Stats.CharacterNamePrefix + m_Diablo2Stats.CharacterName + ", level " + m_Diablo2Stats.CharacterLevel.ToString() + " " + m_Diablo2Stats.CharacterClass + ", a " + m_Diablo2Stats.CharacterModeString + " character in " + m_Diablo2Stats.CharacterActString + ")";
                        break;
                }
            }
        }
    }

    /// <summary>
    /// Provides properties to access Diablo Retail stats.
    /// </summary>
    public class DiabloStats {
        #region Fields
        private int m_Level = -1;
        private int m_Class = -1;
        private int m_Dots = -1;
        private int m_Strength = -1;
        private int m_Magic = -1;
        private int m_Dexterity = -1;
        private int m_Vitality = -1;
        private int m_Gold = -1;
        #endregion

        #region Properties
        /// <summary>Gets the character's level.</summary>
        public int Level {
            get {
                return m_Level;
            }
        }

        /// <summary>Gets the character's class.</summary>
        public string Class {
            get {
                switch (m_Class) {
                    case 1: return "Warrior";
                    case 2: return "Rogue";
                    case 3: return "Sorcerer";
                    default: return "Unknown";
                }
            }
        }

        /// <summary>Gets the character's dots.</summary>
        public int Dots {
            get {
                return m_Dots;
            }
        }

        public string LastDifficultyCompleted {
            get {
                switch (m_Dots) {
                    default:
                    case 0: return "None";
                    case 1: return "Normal";
                    case 2: return "Nightmare";
                    case 3: return "Hell";
                }
            }
        }

        /// <summary>Gets the character's strength.</summary>
        public int Strength {
            get {
                return m_Strength;
            }
        }

        /// <summary>Gets the character's magic.</summary>
        public int Magic {
            get {
                return m_Magic;
            }
        }

        /// <summary>Gets the character's dexterity.</summary>
        public int Dexterity {
            get {
                return m_Dexterity;
            }
        }

        /// <summary>Gets the character's vitality.</summary>
        public int Vitality {
            get {
                return m_Vitality;
            }
        }

        /// <summary>Gets the character's gold.</summary>
        public int Gold {
            get {
                return m_Gold;
            }
        }
        #endregion

        public DiabloStats(int[] data) {
            m_Level = data[1];
            m_Class = data[2];
            m_Dots = data[3];
            m_Strength = data[4];
            m_Magic = data[5];
            m_Dexterity = data[6];
            m_Vitality = data[7];
            m_Gold = data[8];
            //9 = unknown
        }
    }

    /// <summary>
    /// Provides properties to access StarCraft, BroodWar, and Japan stats.
    /// </summary>
    public class StarCraftStats {
        #region Fields
        private int m_Wins = -1;
        private int m_Spawned = -1;
        private string m_Icon = "";
        #endregion

        #region Properties
        /// <summary>Gets the amount of wins.</summary>
        public int Wins {
            get {
                return m_Wins;
            }
        }

        /// <summary>Gets whether the user is on a spawned client.</summary>
        public bool Spawned {
            get {
                switch (m_Spawned) {
                    default:
                    case 0: return false;
                    case 1: return true;
                }
            }
        }

        /// <summary>Gets the name of the user's icon.</summary>
        public string IconName {
            get {
                switch (m_Icon) {
                    case "RHSS":
                    case "RTSJ":
                    case "RATS":
                    case "PXES":
                        return "Normal";
                    default:
                        return "Unknown";
                }
            }
        }
        #endregion

        public StarCraftStats(int[] data, string icon) {
            //1 = ladder rating - StarCraft ladder no longer in existance
            //2 = ladder rank - StarCraft ladder no longer in existance
            m_Wins = data[3];
            m_Spawned = data[4];
            //5 = unknown
            //6 = high ladder rating - StarCraft ladder no longer in existance
            //7 = unknown
            //8 = unknown
            m_Icon = icon;
        }
    }

    /// <summary>
    /// Provides properties to access WarCraft II stats.
    /// </summary>
    public class WarCraft2Stats {
        #region Fields
        private int m_Wins = -1;
        private int m_Spawned = -1;
        private string m_Icon = "";
        #endregion

        #region Properties
        /// <summary>Gets the amount of wins.</summary>
        public int Wins {
            get {
                return m_Wins;
            }
        }

        /// <summary>Gets whether the user is on a spawned client.</summary>
        public bool Spawned {
            get {
                switch (m_Spawned) {
                    default:
                    case 0: return false;
                    case 1: return true;
                }
            }
        }

        /// <summary>Gets the name of the user's icon.</summary>
        public string IconName {
            get {
                switch (m_Icon) {
                    case "NB2W":
                        return "Normal";
                    default:
                        return "Unknown";
                }
            }
        }
        #endregion

        public WarCraft2Stats(int[] data, string icon) {
            //1 = ladder rating - research
            //2 = ladder rank - research
            m_Wins = data[3];
            m_Spawned = data[4];
            //5 = unknown
            //6 = high ladder rating - research
            //7 = iron man rating - research
            //8 = iron man rank - research
            m_Icon = icon;
        }
    }

    /// <summary>
    /// Provides properties to access Diablo II and LOD stats.
    /// </summary>
    public class Diablo2Stats {
        #region Fields
        private bool m_OnRealm;
        private string m_Realm;
        private string m_CharacterName;
        private byte[] m_CharacterBytes;
        #endregion

        #region Properties
        public bool OnRealm {
            get {
                return m_OnRealm;
            }
        }

        public string RealmName {
            get {
                return m_Realm;
            }
        }

        public string CharacterName {
            get {
                return m_CharacterName;
            }
        }

        public string CharacterHeadArmorType {
            get {
                switch (m_CharacterBytes[2]) {
                    case 0x04:
                    case 0x39: return "Cap";
                    case 0x05:
                    case 0x3A: return "Skullcap";
                    case 0x06:
                    case 0x3B: return "Helm";
                    case 0x07:
                    case 0x3C: return "Fullhelm";
                    case 0x08:
                    case 0x3D: return "Greathelm";
                    case 0x0A:
                    case 0x3F: return "Mask";
                    case 0x40:
                    case 0x53: return "Bonehelm";
                    case 0x56: return "Wolf Head";
                    case 0x57: return "Hawkhelm";
                    case 0x58: return "Antlers";
                    case 0x59: return "Fanged Helm";
                    case 0x5A: return "Horned Helm";
                    case 0x5B: return "Avenger Guard";
                    case 0x86: return "Class-Specific 1";
                    case 0x87: return "Class-Specific 2";
                    case 0x88: return "Class-Specific 3";
                    case 0x89: return "Class-Specific 4";
                    case 0x8A: return "Class-Specific 5";
                    case 0x8B: return "Class-Specific 6";
                    case 0x8C: return "Class-Specific 7";
                    case 0x8D: return "Class-Specific 8";
                    case 0x8E: return "Class-Specific 9";
                    case 0x8F: return "Class-Specific 10";
                    case 0x90: return "Class-Specific 11";
                    case 0x91: return "Class-Specific 12";
                    case 0xFF: return "None";
                    default: return "Unknown (" + m_CharacterBytes[2].ToString() + ")";
                }
            }
        }

        public string CharacterChestArmorType {
            get {
                switch (m_CharacterBytes[3]) {
                    case 0x01: return "Leather";
                    case 0x02:
                    case 0x04: return "Chain";
                    case 0x03:
                    case 0x05: return "Plate";
                    case 0x1B:
                    case 0x1C:
                    case 0x1D:
                    case 0x1E:
                    case 0x29:
                    case 0x2A: return "Missing";
                    case 0xFF: return "None";
                    default: return "Unknown (" + m_CharacterBytes[3].ToString() + ")";
                }
            }
        }

        public string CharacterLegArmorType {
            get {
                switch (m_CharacterBytes[4]) {
                    case 255: return "None";
                    default: return "Unknown (" + m_CharacterBytes[4].ToString() + ")";
                }
            }
        }

        public string CharacterArmRArmorType {
            get {
                switch (m_CharacterBytes[5]) {
                    case 0x01: return "Leather";
                    case 0x02:
                    case 0x04: return "Chain";
                    case 0x03:
                    case 0x05: return "Plate";
                    case 0x1B:
                    case 0x1C:
                    case 0x1D:
                    case 0x1E:
                    case 0x29:
                    case 0x2A: return "Missing";
                    case 0xFF: return "None";
                    default: return "Unknown (" + m_CharacterBytes[5].ToString() + ")";
                }
            }
        }

        public string CharacterArmLArmorType {
            get {
                switch (m_CharacterBytes[6]) {
                    case 0x01: return "Leather";
                    case 0x02:
                    case 0x04: return "Chain";
                    case 0x03:
                    case 0x05: return "Plate";
                    case 0x1B:
                    case 0x1C:
                    case 0x1D:
                    case 0x1E:
                    case 0x29:
                    case 0x2A: return "Missing";
                    case 0xFF: return "None";
                    default: return "Unknown (" + m_CharacterBytes[6].ToString() + ")";
                }
            }
        }

        public string CharacterWeaponRType {
            get {
                switch (m_CharacterBytes[7]) {
                    case 0x04: return "Hand Axe";
                    case 0x05: return "Axe";
                    case 0x06: return "Double Axe";
                    case 0x07: return "War Axe";
                    case 0x08: return "Great Axe";
                    case 0x09: return "Wand";
                    case 0x0A: return "Yew Wand";
                    case 0x0B: return "Grim Wand";
                    case 0x0C: return "Spiked Club";
                    case 0x0D: return "Scepter";
                    case 0x0E: return "War Hammer";
                    case 0x0F: return "Flail";
                    case 0x10: return "Maul";
                    case 0x11: return "Short Sword";
                    case 0x12: return "Scimitar";
                    case 0x13: return "Falchion";
                    case 0x14: return "Crystal Sword";
                    case 0x15: return "Broad Sword";
                    case 0x16: return "Long Sword";
                    case 0x17: return "Claymore";
                    case 0x18: return "Bastard Sword";
                    case 0x19: return "Dagger";
                    case 0x1A: return "Blade";
                    case 0x1B: return "Short Spear";
                    case 0x1C: return "Glaive";
                    case 0x1D: return "Pilum";
                    case 0x1E: return "Spear";
                    case 0x1F: return "Trident";
                    case 0x20: return "Spetum";
                    case 0x21: return "Pike";
                    case 0x22: return "Bardiche";
                    case 0x23: return "Scythe";
                    case 0x24: return "Halberd";
                    case 0x25: return "Short Staff";
                    case 0x26: return "Long Staff";
                    case 0x27: return "Battle Staff";
                    case 0x28: return "War Staff";
                    case 0x29: return "Short Bow";
                    case 0x2A: return "Long Bow";
                    case 0x2B:
                    case 0xF3:
                    case 0xF4:
                    case 0xFB: return "Claw";
                    case 0x2C:
                    case 0xF5:
                    case 0xF6:
                    case 0xFC: return "Scissors Katar";
                    case 0x2D:
                    case 0xF7:
                    case 0xF8:
                    case 0xFD: return "Katar";
                    case 0x2E:
                    case 0xF9:
                    case 0xFA:
                    case 0xFE: return "Hatchet Hand";
                    case 0x2F: return "Hunter's Bow";
                    case 0x30: return "Composite Bow";
                    case 0x31:
                    case 0x7A:
                    case 0xF0: return "Crossbow";
                    case 0x32:
                    case 0x7B:
                    case 0x7C:
                    case 0xF1: 
                    case 0xF2: return "Heavy Crossbow";
                    case 0x33: return "Eagle Orb";
                    case 0x34: return "Sacred Globe";
                    case 0x35: return "Clasped Orb";
                    case 0x36: return "Stag Bow";
                    case 0x37: return "Reflex Bow";
                    case 0x75:
                    case 0xEB: return "Short Battle Bow";
                    case 0x76:
                    case 0xEC: return "Long Battle Bow";
                    case 0x77:
                    case 0xED: return "Short War Bow";
                    case 0x78:
                    case 0xEE: return "Long War Bow";
                    case 0x79:
                    case 0xEF: return "Light Crossbow";
                    case 0x7D:
                    case 0x7F:
                    case 0x81: return "Poison Potion";
                    case 0x7E:
                    case 0x80: return "Fulminating Potion";
                    case 0x86: return "Something Round";
                    case 255: return "None";
                    default: return "Unknown (" + m_CharacterBytes[7].ToString() + ")";
                }
            }
        }

        public string CharacterWeaponLType {
            get {
                switch (m_CharacterBytes[8]) {
                    case 0x04: return "Hand Axe";
                    case 0x05: return "Axe";
                    case 0x06: return "Double Axe";
                    case 0x07: return "War Axe";
                    case 0x08: return "Great Axe";
                    case 0x09: return "Wand";
                    case 0x0A: return "Yew Wand";
                    case 0x0B: return "Grim Wand";
                    case 0x0C: return "Spiked Club";
                    case 0x0D: return "Scepter";
                    case 0x0E: return "War Hammer";
                    case 0x0F: return "Flail";
                    case 0x10: return "Maul";
                    case 0x11: return "Short Sword";
                    case 0x12: return "Scimitar";
                    case 0x13: return "Falchion";
                    case 0x14: return "Crystal Sword";
                    case 0x15: return "Broad Sword";
                    case 0x16: return "Long Sword";
                    case 0x17: return "Claymore";
                    case 0x18: return "Bastard Sword";
                    case 0x19: return "Dagger";
                    case 0x1A: return "Blade";
                    case 0x1B: return "Short Spear";
                    case 0x1C: return "Glaive";
                    case 0x1D: return "Pilum";
                    case 0x1E: return "Spear";
                    case 0x1F: return "Trident";
                    case 0x20: return "Spetum";
                    case 0x21: return "Pike";
                    case 0x22: return "Bardiche";
                    case 0x23: return "Scythe";
                    case 0x24: return "Halberd";
                    case 0x25: return "Short Staff";
                    case 0x26: return "Long Staff";
                    case 0x27: return "Battle Staff";
                    case 0x28: return "War Staff";
                    case 0x29: return "Short Bow";
                    case 0x2A: return "Long Bow";
                    case 0x2B:
                    case 0xF3:
                    case 0xF4:
                    case 0xFB: return "Claw";
                    case 0x2C:
                    case 0xF5:
                    case 0xF6:
                    case 0xFC: return "Scissors Katar";
                    case 0x2D:
                    case 0xF7:
                    case 0xF8:
                    case 0xFD: return "Katar";
                    case 0x2E:
                    case 0xF9:
                    case 0xFA:
                    case 0xFE: return "Hatchet Hand";
                    case 0x2F: return "Hunter's Bow";
                    case 0x30: return "Composite Bow";
                    case 0x31:
                    case 0x7A:
                    case 0xF0: return "Crossbow";
                    case 0x32:
                    case 0x7B:
                    case 0x7C:
                    case 0xF1:
                    case 0xF2: return "Heavy Crossbow";
                    case 0x33: return "Eagle Orb";
                    case 0x34: return "Sacred Globe";
                    case 0x35: return "Clasped Orb";
                    case 0x36: return "Stag Bow";
                    case 0x37: return "Reflex Bow";
                    case 0x75:
                    case 0xEB: return "Short Battle Bow";
                    case 0x76:
                    case 0xEC: return "Long Battle Bow";
                    case 0x77:
                    case 0xED: return "Short War Bow";
                    case 0x78:
                    case 0xEE: return "Long War Bow";
                    case 0x79:
                    case 0xEF: return "Light Crossbow";
                    case 0x7D:
                    case 0x7F:
                    case 0x81: return "Poison Potion";
                    case 0x7E:
                    case 0x80: return "Fulminating Potion";
                    case 0x86: return "Something Round";
                    case 255: return "None";
                    default: return "Unknown (" + m_CharacterBytes[8].ToString() + ")";
                }
            }
        }

        public string CharacterShieldType {
            get {
                switch (m_CharacterBytes[9]) {
                    case 0x4F: return "Small Shield";
                    case 0x50: return "Buckler";
                    case 0x51: return "Kite Shield";
                    case 0x52: return "Tower Shield";
                    case 0x54: return "Bone Shield";
                    case 0x55: return "Spiked Shield";
                    case 0x5C: return "Targe";
                    case 0x5D: return "Heraldic Shield";
                    case 0x5E: return "Crown Shield";
                    case 0xFF: return "None";
                    default: return "Unknown (" + m_CharacterBytes[9].ToString() + ")";
                }
            }
        }

        public string CharacterShpadRType {
            get {
                switch (m_CharacterBytes[10]) {
                    case 0x02: return "Chain";
                    case 0x03: return "Plate";
                    default: return "Leather";
                }
            }
        }

        public string CharacterShpadLType {
            get {
                switch (m_CharacterBytes[11]) {
                    case 0x02: return "Chain";
                    case 0x03: return "Plate";
                    default: return "Leather";
                }
            }
        }

        public string CharacterClass {
            get {
                switch (m_CharacterBytes[13]) {
                    case 1: return "Amazon";
                    case 2: return "Sorceress";
                    case 3: return "Necromancer";
                    case 4: return "Paladin";
                    case 5: return "Barbarian";
                    case 6: return "Druid";
                    case 7: return "Assassin";
                    default: return "Unknown (" + m_CharacterBytes[13] + ")";
                }
            }
        }

        public Diablo2CharacterSex CharacterSex {
            get {
                switch (m_CharacterBytes[13]) {
                    case 1:
                    case 2:
                    case 7: return Diablo2CharacterSex.Female;
                    case 3:
                    case 4:
                    case 5:
                    case 6: return Diablo2CharacterSex.Male;
                    default: return Diablo2CharacterSex.Unknown;
                }
            }
        }

        public string CharacterHeadColor {
            get {
                return GetColorFromByte(m_CharacterBytes[14]);
            }
        }

        public string CharacterChestColor {
            get {
                return GetColorFromByte(m_CharacterBytes[15]);
            }
        }

        public string CharacterLegColor {
            get {
                return GetColorFromByte(m_CharacterBytes[16]);
            }
        }

        public string CharacterArmRColor {
            get {
                return GetColorFromByte(m_CharacterBytes[17]);
            }
        }

        public string CharacterArmLColor {
            get {
                return GetColorFromByte(m_CharacterBytes[18]);
            }
        }

        public string CharacterWeaponRColor {
            get {
                return GetColorFromByte(m_CharacterBytes[19]);
            }
        }

        public string CharacterWeaponLColor {
            get {
                return GetColorFromByte(m_CharacterBytes[20]);
            }
        }

        public string CharacterShieldColor {
            get {
                return GetColorFromByte(m_CharacterBytes[21]);
            }
        }

        public string CharacterShpadRColor {
            get {
                return GetColorFromByte(m_CharacterBytes[22]);
            }
        }

        public string CharacterShpadLColor {
            get {
                return GetColorFromByte(m_CharacterBytes[23]);
            }
        }

        public int CharacterLevel {
            get {
                return (int) m_CharacterBytes[25];
            }
        }

        public Diablo2CharacterMode CharacterMode {
            get {
                return (Diablo2CharacterMode) m_CharacterBytes[26];
            }
        }

        public string CharacterModeString {
            get {
                string mode = "";
                if (CharacterLadder)
                    mode += "Ladder, ";
                else
                    mode += "Non-ladder, ";
                if ((CharacterMode & Diablo2CharacterMode.Expansion) == Diablo2CharacterMode.Expansion)
                    mode += "Expansion, ";
                if ((CharacterMode & Diablo2CharacterMode.Hardcore) == Diablo2CharacterMode.Hardcore) {
                    if ((CharacterMode & Diablo2CharacterMode.Dead) == Diablo2CharacterMode.Dead)
                        mode += "Dead ";
                    mode += "Hardcore, ";
                }
                mode = mode.Substring(0, mode.Length - 2);
                return mode;
            }
        }

        public int CharacterAct {
            get {
                if (((Diablo2CharacterMode) CharacterMode & Diablo2CharacterMode.Expansion) == Diablo2CharacterMode.Expansion) {
                    switch (m_CharacterBytes[27]) {
                        case 0x80:
                        case 0x8A:
                        case 0x94:
                            return 1;
                        case 0x82:
                        case 0x8C:
                        case 0x96:
                            return 2;
                        case 0x84:
                        case 0x8E:
                        case 0x98:
                            return 3;
                        case 0x86:
                        case 0x90:
                        case 0x9A:
                            return 4;
                        case 0x88:
                        case 0x92:
                        case 0x9C:
                            return 5;
                        case 0x9E:
                            return 6;
                        default:
                            return -1;
                    }
                } else {
                    switch (m_CharacterBytes[27]) {
                        case 0x80:
                        case 0x88:
                        case 0x90:
                            return 1;
                        case 0x82:
                        case 0x8A:
                        case 0x92:
                            return 2;
                        case 0x84:
                        case 0x8C:
                        case 0x94:
                            return 3;
                        case 0x86:
                        case 0x8E:
                        case 0x96:
                            return 4;
                        case 0x98:
                            return 6;
                        default:
                            return -1;
                    }
                }
            }
        }

        public string CharacterActString {
            get {
                if (CharacterAct == 6)
                    return "All Acts";
                else
                    return CharacterDifficulty + " Act " + CharacterAct.ToString();
            }
        }

        public string CharacterDifficulty {
            get {
                if (((Diablo2CharacterMode) CharacterMode & Diablo2CharacterMode.Expansion) == Diablo2CharacterMode.Expansion) {
                    switch (m_CharacterBytes[27]) {
                        case 0x80:
                        case 0x82:
                        case 0x84:
                        case 0x86:
                        case 0x88:
                            return "Normal";
                        case 0x8A:
                        case 0x8C:
                        case 0x8E:
                        case 0x90:
                        case 0x92:
                            return "Nightmare";
                        case 0x94:
                        case 0x96:
                        case 0x98:
                        case 0x9A:
                        case 0x9C:
                            return "Hell";
                        case 0x9E:
                            return "All Acts";
                        default:
                            return "Unknown Act";
                    }
                } else {
                    switch (m_CharacterBytes[27]) {
                        case 0x80:
                        case 0x82:
                        case 0x84:
                        case 0x86:
                            return "Normal";
                        case 0x88:
                        case 0x8A:
                        case 0x8C:
                        case 0x8E:
                            return "Nightmare";
                        case 0x90:
                        case 0x92:
                        case 0x94:
                        case 0x96:
                            return "Hell";
                        case 0x98:
                            return "All Acts";
                        default:
                            return "Unknown Act";
                    }
                }
            }
        }

        public string CharacterNamePrefix {
            get {
                if (((Diablo2CharacterMode) CharacterMode & Diablo2CharacterMode.Expansion) == Diablo2CharacterMode.Expansion) {
                    if (((Diablo2CharacterMode) CharacterMode & Diablo2CharacterMode.Hardcore) == Diablo2CharacterMode.Hardcore) {
                        switch (m_CharacterBytes[27]) {
                            case 0x80:
                            case 0x82:
                            case 0x84:
                            case 0x86:
                            case 0x88:
                                return "";
                            case 0x8A:
                            case 0x8C:
                            case 0x8E:
                            case 0x90:
                            case 0x92:
                                return "Destroyer ";
                            case 0x94:
                            case 0x96:
                            case 0x98:
                            case 0x9A:
                            case 0x9C:
                                return "Conquerer ";
                            case 0x9E:
                                return "Guardian ";
                            default:
                                return "Unknown ";
                        }
                    } else {
                        switch (m_CharacterBytes[27]) {
                            case 0x80:
                            case 0x82:
                            case 0x84:
                            case 0x86:
                            case 0x88:
                                return "";
                            case 0x8A:
                            case 0x8C:
                            case 0x8E:
                            case 0x90:
                            case 0x92:
                                return "Slayer ";
                            case 0x94:
                            case 0x96:
                            case 0x98:
                            case 0x9A:
                            case 0x9C:
                                return "Champion ";
                            case 0x9E:
                                if (CharacterSex == Diablo2CharacterSex.Male)
                                    return "Patriarch ";
                                else
                                    return "Matriarch ";
                            default:
                                return "Unknown ";
                        }
                    }
                } else {
                    if (((Diablo2CharacterMode) CharacterMode & Diablo2CharacterMode.Hardcore) == Diablo2CharacterMode.Hardcore) {
                        switch (m_CharacterBytes[27]) {
                            case 0x80:
                            case 0x82:
                            case 0x84:
                            case 0x86:
                            case 0x88:
                                return "";
                            case 0x8A:
                            case 0x8C:
                            case 0x8E:
                            case 0x90:
                            case 0x92:
                                return "hcnm ";
                            case 0x94:
                            case 0x96:
                            case 0x98:
                            case 0x9A:
                            case 0x9C:
                                return "hchell ";
                            case 0x9E:
                                return "hcall ";
                            default:
                                return "Unknown ";
                        }
                    } else {
                        switch (m_CharacterBytes[27]) {
                            case 0x80:
                            case 0x82:
                            case 0x84:
                            case 0x86:
                            case 0x88:
                                return "";
                            case 0x8A:
                            case 0x8C:
                            case 0x8E:
                            case 0x90:
                            case 0x92:
                                return "scnm ";
                            case 0x94:
                            case 0x96:
                            case 0x98:
                            case 0x9A:
                            case 0x9C:
                                return "schell ";
                            case 0x9E:
                                if (CharacterSex == Diablo2CharacterSex.Male)
                                    return "scallm ";
                                else
                                    return "scallf ";
                            default:
                                return "Unknown ";
                        }
                    }
                }
            }
        }

        public bool CharacterLadder {
            get {
                return (m_CharacterBytes[30] != 0xFF);
            }
        }
        #endregion

        public static string GetColorFromByte(byte characterByte) {
            byte tintno = 0;
            Color value = Color.Empty;
            string valueName;

            if ((characterByte & 0xE0) == 0xE0) {
                characterByte = (byte) (characterByte - 0xE0);
                tintno = 7;
            } else if ((characterByte & 0xC0) == 0xC0) {
                characterByte = (byte) (characterByte - 0xC0);
                tintno = 6;
            } else if ((characterByte & 0xA0) == 0xA0) {
                characterByte = (byte) (characterByte - 0xA0);
                tintno = 5;
            } else if ((characterByte & 0x80) == 0x80) {
                characterByte = (byte) (characterByte - 0x80);
                tintno = 4;
            } else if ((characterByte & 0x60) == 0x60) {
                characterByte = (byte) (characterByte - 0x60);
                tintno = 3;
            } else if ((characterByte & 0x40) == 0x40) {
                characterByte = (byte) (characterByte - 0x40);
                tintno = 2;
            } else if ((characterByte & 0x20) == 0x20) {
                characterByte = (byte) (characterByte - 0x20);
                tintno = 1;
            } else {
                tintno = 8;
            }

            switch (characterByte) {
                case 0x01: value = Color.Gray; break;
                case 0x02: value = Color.DimGray; break;
                case 0x03: value = Color.DarkGray; break;
                case 0x04: value = Color.Black; break;
                case 0x05:
                case 0x06:
                case 0x07: value = Color.Blue; break;
                case 0x08:
                case 0x09:
                case 0x0A: value = Color.Red; break;
                case 0x0B:
                case 0x0C:
                case 0x0D: value = Color.Green; break;
                case 0x0E:
                case 0x0F:
                case 0x10:
                case 0x11:
                case 0x2E: value = Color.Yellow; break;
                case 0x12:
                case 0x13:
                case 0x32: value = Color.Purple; break;
                case 0x14: value = Color.Gold; break;
                case 0x15: value = Color.White; break;
            }

            if (value != Color.Empty)
                valueName = value.Name;
            else
                valueName = "Unknown";

            switch (tintno){
                case 0: return "Normal " + valueName;
                case 1: return "Tinted (1) " + valueName;
                case 2: return "Tinted (2) " + valueName;
                case 3: return "Tinted (3) " + valueName;
                case 4: return "Tinted (4) " + valueName;
                case 5: return "Tinted (5) " + valueName;
                case 6: return "Tinted (6) " + valueName;
                case 7: return "Tinted (7) " + valueName;
                default: return "Unknown (" + characterByte + ")";
            }
        }

        public Diablo2Stats() {
            m_OnRealm = false;
        }

        public Diablo2Stats(string[] data) {
            m_OnRealm = true;

            m_Realm = data[0];
            m_CharacterName = data[1];

            m_CharacterBytes = new byte[data[2].Length];
            for (int i = 0; i < data[2].Length; i++) {
                m_CharacterBytes[i] = (byte) data[2][i];
            }
        }
    }

    public enum Diablo2CharacterMode : byte {
        Hardcore = 0x04,
        Dead = 0x08,
        Expansion = 0x20
    }

    public enum Diablo2CharacterSex {
        Unknown = 0,
        Male = 1,
        Female = 2
    }

    /// <summary>
    /// Provides properties to access WarCraft III and TFT stats.
    /// </summary>
    public class WarCraft3Stats {
        #region Fields
        private string m_Icon = "";
        private int m_Level = -1;
        private string m_Tag = "";
        private string m_Game = "";
        #endregion

        #region Properties
        /// <summary>Gets the name of the user's icon.</summary>
        public string IconName {
            get {
                if (m_Icon == "")
                    m_Icon = m_Game;
                if (m_Icon == "3RAW" || m_Icon == "PX3W")
                    return "Normal";
                byte tier = 0;
                if (m_Game == "3RAW") {
                    if (byte.TryParse(m_Icon[0].ToString(), out tier)) {
                        switch (tier) {
                            case 1:
                                return "Peon";
                            case 2:
                                switch (m_Icon[1]) {
                                    case 'O':
                                        return "Grunt";
                                    case 'H':
                                        return "Footman";
                                    case 'U':
                                        return "Ghoul";
                                    case 'N':
                                        return "Archer";
                                    case 'R':
                                        return "Green Dragon Whelp";
                                    default:
                                        return "Unknown";
                                }
                            case 3:
                                switch (m_Icon[1]) {
                                    case 'O':
                                        return "Tauren";
                                    case 'H':
                                        return "Knight";
                                    case 'U':
                                        return "Abomination";
                                    case 'N':
                                        return "Druid of the Claw";
                                    case 'R':
                                        return "Blue Dragon";
                                    default:
                                        return "Unknown";
                                }
                            case 4:
                                switch (m_Icon[1]) {
                                    case 'O':
                                        return "Far Seer";
                                    case 'H':
                                        return "Archmage";
                                    case 'U':
                                        return "Lich";
                                    case 'N':
                                        return "Priestess of the Moon";
                                    case 'R':
                                        return "Red Dragon";
                                    default:
                                        return "Unknown";
                                }
                            case 5:
                                switch (m_Icon[1]) {
                                    case 'O':
                                        return "Thrall";
                                    case 'H':
                                        return "Medivh";
                                    case 'U':
                                        return "Tichondrius";
                                    case 'N':
                                        return "Furion Stormrage";
                                    case 'R':
                                        return "Deathwing";
                                    default:
                                        return "Unknown";
                                }
                            default:
                                return "Unknown";
                        }
                    } else {
                        return "Unknown";
                    }
                } else {
                    if (byte.TryParse(m_Icon[0].ToString(), out tier)) {
                        switch (tier) {
                            case 1:
                                return "Peon";
                            case 2:
                                switch (m_Icon[1]) {
                                    case 'O':
                                        return "Troll Headhunter";
                                    case 'H':
                                        return "Rifleman";
                                    case 'U':
                                        return "Crypt Fiend";
                                    case 'N':
                                        return "Huntress";
                                    case 'R':
                                        return "Myrmidon";
                                    case 'T':
                                        return "Felguard";
                                    default:
                                        return "Unknown";
                                }
                            case 3:
                                switch (m_Icon[1]) {
                                    case 'O':
                                        return "Shaman";
                                    case 'H':
                                        return "Sorceress";
                                    case 'U':
                                        return "Banshee";
                                    case 'N':
                                        return "Druid of the Talon";
                                    case 'R':
                                        return "Siren";
                                    case 'T':
                                        return "Infernal";
                                    default:
                                        return "Unknown";
                                }
                            case 4:
                                switch (m_Icon[1]) {
                                    case 'O':
                                        return "Spirit Walker";
                                    case 'H':
                                        return "Spellbreaker";
                                    case 'U':
                                        return "Destroyer";
                                    case 'N':
                                        return "Dryad";
                                    case 'R':
                                        return "Dragon Turtle";
                                    case 'T':
                                        return "Doomguard";
                                    default:
                                        return "Unknown";
                                }
                            case 5:
                                switch (m_Icon[1]) {
                                    case 'O':
                                        return "Shadow Hunter";
                                    case 'H':
                                        return "Blood Mage";
                                    case 'U':
                                        return "Crypt Lord";
                                    case 'N':
                                        return "Keeper of the Grove";
                                    case 'R':
                                        return "Sea Witch";
                                    case 'T':
                                        return "Pit Lord";
                                    default:
                                        return "Unknown";
                                }
                            case 6:
                                switch (m_Icon[1]) {
                                    case 'O':
                                        return "Rexxar";
                                    case 'H':
                                        return "Jaina";
                                    case 'U':
                                        return "Sylvanas";
                                    case 'N':
                                        return "Maiev";
                                    case 'R':
                                        return "Illidan";
                                    case 'T':
                                        return "Archimonde";
                                    default:
                                        return "Unknown";
                                }
                            default:
                                return "Unknown";
                        }
                    } else {
                        return "Unknown";
                    }
                }
            }
        }

        /// <summary>Gets the number of wins required for the user's icon.</summary>
        public int IconWins {
            get {
                if (m_Icon == "")
                    m_Icon = m_Game;
                if (m_Icon == "3RAW" || m_Icon == "PX3W")
                    return -1;
                byte tier = 0;
                if (m_Game == "3RAW") {
                    if (byte.TryParse(m_Icon[0].ToString(), out tier)) {
                        switch (tier) {
                            case 1: return 0;
                            case 2: return 25;
                            case 3: return 250;
                            case 4: return 500;
                            case 5: return 1500;
                            default: return 0;
                        }
                    } else {
                        return 0;
                    }
                } else {
                    if (byte.TryParse(m_Icon[0].ToString(), out tier)) {
                        switch (tier) {
                            case 1:
                                return 0;
                            case 2:
                                switch (m_Icon[1]) {
                                    case 'T':
                                        return 10;
                                    default:
                                        return 25;
                                }
                            case 3:
                                switch (m_Icon[1]) {
                                    case 'T':
                                        return 75;
                                    default:
                                        return 150;
                                }
                            case 4:
                                switch (m_Icon[1]) {
                                    case 'T':
                                        return 150;
                                    default:
                                        return 350;
                                }
                            case 5:
                                switch (m_Icon[1]) {
                                    case 'T':
                                        return 250;
                                    default:
                                        return 750;
                                }
                            case 6:
                                switch (m_Icon[1]) {
                                    case 'T':
                                        return 500;
                                    default:
                                        return 1500;
                                }
                            default:
                                return 0;
                        }
                    } else {
                        return 0;
                    }
                }
            }
        }

        /// <summary>Gets the tier of the user's icon.</summary>
        public int IconTier {
            get {
                if (m_Icon == "")
                    m_Icon = m_Game;
                if (m_Icon == "3RAW" || m_Icon == "PX3W")
                    return -1;
                byte tier = 0;
                byte.TryParse(m_Icon[0].ToString(), out tier);
                return tier;
            }
        }

        /// <summary>Gets the race of the user's icon.</summary>
        public string IconRace {
            get {
                if (m_Icon == "")
                    m_Icon = m_Game;
                if (m_Icon == "3RAW" || m_Icon == "PX3W")
                    return "None";
                switch (m_Icon[1]) {
                    case 'O':
                        return "Orc";
                    case 'H':
                        return "Human";
                    case 'U':
                        return "Undead";
                    case 'N':
                        return "Night Elf";
                    case 'R':
                        return "Random";
                    case 'T':
                        return "Tournament";
                    default:
                        return "Unknown";
                }
            }
        }

        /// <summary>Gets the user's level.</summary>
        public int Level {
            get {
                return m_Level;
            }
        }

        /// <summary>Gets the user's clan tag.</summary>
        public string ClanTag {
            get {
                return m_Tag;
            }
        }
        #endregion

        public WarCraft3Stats(string[] stats) {
            m_Game = stats[0];
            switch (stats.Length) {
                case 1:
                    break;
                case 3:
                    m_Icon = stats[1];
                    m_Level = int.Parse(stats[2]);
                    break;
                case 4:
                    m_Icon = stats[1];
                    m_Level = int.Parse(stats[2]);
                    if (stats[3] != null)
                        for (int j = stats[3].Length - 1; j >= 0; j--)
                            m_Tag += stats[3][j];
                    break;
            }
        }
    }
}
